﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：CompanyCheckeList.aspx.cs
    // 文件功能描述：审核企业
    // 创建标识：吕海乐2009-05-31
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;


namespace HZ.DrugTrade.Web.Admin.SystemManage
{
    public partial class CompanyCheckList : BasePage
    {
        public CompanyCheckList()
        {
            this.ModuleNo = Module.系统管理.ToString();
            this.PageOperateType = OperateType.企业管理.ToString();
        }

        IBLL_Company ic = Factory.BLL_Company();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindCompanyInfo();
                if (gvwCheckList.Rows.Count <= 0)
                {
                    btnBatResetPws.Visible = false;
                    btnBatUnLock.Visible = false;
                }
            }
        }

        /// <summary>
        /// 获取未审核的企业
        /// </summary>
        private void BindCompanyInfo()
        {
            //从页面获取分页大小
            int iPageSize = Convert.ToInt32(this.dplPageSize.SelectedValue);
            int totalCount;
            AspNetPager1.PageSize = iPageSize;
            Model.Query.CompanyInfo qCompanyInfo = new HZ.DrugTrade.Model.Query.CompanyInfo();
            qCompanyInfo.CompanyName = txtCompanyName.Text.Trim();
            qCompanyInfo.SortFields = "AddTime DESC";
            IList<CompanyInfo> lstCompanyInfo = ic.GetUnregedCompanyInfo(qCompanyInfo, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwCheckList.DataSource = lstCompanyInfo;
            gvwCheckList.DataBind();
        }
        /// <summary>
        /// 审核通过
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnBatUnLock_Click(object sender, EventArgs e)
        {
            IList<CompanyInfo> lstCompanyInfo = new List<CompanyInfo>();

            //string[] arrayCompanyName = companyNames.Split(',');
            //foreach (string item in arrayCompanyName)
            //{
            //    CompanyInfo aCompanyInfo = new CompanyInfo();
            //    aCompanyInfo.CompanyName = item;
            //    lstCompanyInfo.Add(aCompanyInfo);
            //}

            for (int i = 0; i < this.gvwCheckList.Rows.Count; i++)
            {
                System.Web.UI.HtmlControls.HtmlInputCheckBox chk = (System.Web.UI.HtmlControls.HtmlInputCheckBox)gvwCheckList.Rows[i].FindControl("chkChildUser");
                Label lbCellNo = gvwCheckList.Rows[i].FindControl("lbCellNo") as Label;
                if (chk.Checked == true)
                {
                    CompanyInfo aCompanyInfo = new CompanyInfo();
                    aCompanyInfo.CompanyName = chk.Value;
                    aCompanyInfo.CellNo = lbCellNo.Text.Trim();
                    lstCompanyInfo.Add(aCompanyInfo);
                }
            }
            string outUserids;
            int flag = ic.AduitCompany(lstCompanyInfo,out outUserids);
            if (flag == 1)
            {
                PageInfo("批量审核执行成功！" + "\n" + "对应的用户名：" + outUserids, "CompanyCheckList.aspx");
                //刷新绑定
                //BindCompanyInfo();
            }
            else
            {
                PageError("审核失败！", "CompanyCheckList.aspx");
            }

        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnBatResetPws_Click(object sender, EventArgs e)
        {
            IList<CompanyInfo> lstCompanyInfo = new List<CompanyInfo>();
            string companyNames = Request["chkChildUser"];

            for (int i = 0; i < this.gvwCheckList.Rows.Count; i++)
            {
                System.Web.UI.HtmlControls.HtmlInputCheckBox chk = (System.Web.UI.HtmlControls.HtmlInputCheckBox)gvwCheckList.Rows[i].FindControl("chkChildUser");
                Label lbCellNo = gvwCheckList.Rows[i].FindControl("lbCellNo") as Label;
                if (chk.Checked == true)
                {
                    CompanyInfo aCompanyInfo = new CompanyInfo();
                    aCompanyInfo.CompanyName = chk.Value;
                    aCompanyInfo.CellNo = lbCellNo.Text.Trim();
                    lstCompanyInfo.Add(aCompanyInfo);
                }
            }

            //if (!string.IsNullOrEmpty(companyNames))
            if (lstCompanyInfo.Count>0)
            {
                //string[] arrayCompanyName = companyNames.Split(',');
                //foreach (string item in arrayCompanyName)
                //{
                //    CompanyInfo aCompanyInfo = new CompanyInfo();
                //    aCompanyInfo.CompanyName = item;
                //    lstCompanyInfo.Add(aCompanyInfo);
                //}

                int flag = ic.DeleteCompanyInfo(lstCompanyInfo);
                if (flag == 1)
                {
                    PageInfo("删除成功！", "CompanyCheckList.aspx");
                }
                else
                {
                    PageError("删除失败！", "CompanyCheckList.aspx");
                }
            }
            else
            {
                HZ.Web.WebUtil.Alert("请至少选择一个需删除的企业！", this);
                return;
            }
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            BindCompanyInfo();
        }
    }
}
